import { defineStore } from "pinia";
import { ref } from 'vue'

export const Travel = defineStore("travel", {
    state: () => {
        return {
            userId: '',
            travelReason: '',
            startDate: '',
            endDate: '',
            travelDetail: '',
            foodCost: 0,
            transportCost: 0,
            hotelCost: 0,
            costDetail: '',
            advancePayment:0,
            applyDate:'',
            isAdvance: false,
        }
    },
    actions: {
        setTravel(userId, travelReason, startDate, endDate, travelDetail) {
            this.userId = userId;
            this.travelReason = travelReason;
            this.startDate = startDate;
            this.endDate = endDate;
            this.travelDetail = travelDetail;
        },

        setBudget(foodCost, transportCost, hotelCost, costDetail, advancePayment) {
            this.foodCost = foodCost;
            this.transportCost = transportCost;
            this.hotelCost = hotelCost;
            this.costDetail = costDetail;
            this.advancePayment = advancePayment;
        },

        setLocalDate() {
            const currentDate = new Date();
            const year = currentDate.getFullYear();
            const month = currentDate.getMonth() + 1;  // 月份从 0 开始，需要加 1
            const day = currentDate.getDate();
            this.applyDate = `${year}-${month}-${day}`;
        },


    },
    persist: {
        enabled: true,
    }
});
